package com.cencat.framework.core.controller;

import com.cencat.framework.core.dto.PageQuery;
import com.cencat.framework.core.dto.PageResult;
import com.cencat.framework.core.dto.Result;
import com.cencat.framework.core.entity.TenantBaseEntity;
import com.cencat.framework.core.service.TenantBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

public abstract class TenantBaseController<T extends TenantBaseEntity> extends BaseController<T> {
    
    @Autowired
    private TenantBaseService<T> tenantBaseService;
    
    /**
     * 根据租户ID查询列表
     */
    @GetMapping("/tenant/{tenantId}")
    public Result<List<T>> listByTenantId(@PathVariable Long tenantId) {
        List<T> list = tenantBaseService.listByTenantId(tenantId);
        return Result.success(list);
    }
    
    /**
     * 根据租户编码查询列表
     */
    @GetMapping("/tenant/code/{tenantCode}")
    public Result<List<T>> listByTenantCode(@PathVariable String tenantCode) {
        List<T> list = tenantBaseService.listByTenantCode(tenantCode);
        return Result.success(list);
    }
    
    /**
     * 租户分页查询
     */
    @PostMapping("/tenant/page")
    public Result<PageResult<T>> pageByTenant(@RequestBody PageQuery pageQuery, @RequestParam Long tenantId) {
        PageResult<T> pageResult = tenantBaseService.pageByTenant(pageQuery, tenantId);
        return Result.success(pageResult);
    }
}